<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
    <head>
        <title></title>
        <meta charset="utf-8">
        <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <link rel="stylesheet" href="css/fonts/font-awesome.min.css">
        <link rel="stylesheet" href="css/ui-box.css">
        <link rel="stylesheet" href="css/ui-base.css">
        <link rel="stylesheet" href="css/ui-color.css">
        <link rel="stylesheet" href="css/appcan.icon.css">
        <link rel="stylesheet" href="css/appcan.control.css">
        <link rel="stylesheet" href="sell_content/css/main.css">
    </head>
    <body class="um-vp bc-bg" ontouchstart>
        <div class="ub ub-ver uinn-a1">
            <div class="uba b-gra3 uc-a1 c-wh ub uinn-a7 ub-ac">
                <div class="ulev-app1 umw4">
                   ISBN码
                </div>
                <div class="ub ub-ac umh5 ub-f1">
                    <div class="uinput ub ub-f1">
                        <input placeholder="条形码下面的13位数字" type="text" class="ub-f1" id='scanner'>
                    </div>

                </div>
            </div>
            <div class="btn ub ub-ac bc-text-head ub-pc bc-btn"  id="saoyisao">
	                                   扫一扫
            </div>

            <div class="uba b-gra3 uc-a1 c-wh ub uinn-a7 ub-ac umar-at1">
                <div class="ulev-app1 umw4">
                    价格
                </div>
                <div class="ub ub-ac umh5 ub-f1">
                    <div class="uinput ub ub-f1">
                        <input placeholder="23.33" type="text" class="ub-f1" id="price">
                    </div>
                </div>
            </div>
            
            <div id="listview1"></div>
            
            <div class="ub ub-ver">
                <div class="ub ub-pe uinn-a6 ulev-4">
                    <div class="sc-text">
                        我同意
                    </div>
                    <div class="sc-text-active">
                        用户服务协议
                    </div>
                </div>
                <div class="uinn-at1">
                    <div class="btn ub ub-ac bc-text-head ub-pc bc-btn"  id="submit">
                        提交信息
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script src="js/appcan.js"></script>
    <script src="js/appcan.control.js"></script>
    <script src="js/appcan.listview.js"></script>
    </body>
    <script>
        
        var cText = 0;
        var cJson = 1;
        var cInt = 2;
        var price;
        var a = 0.5;
        var b = 0.5;
        var c = 0.5;
        var d = 0.5;
        
        var username = localStorage.getItem("username");
        var flag;
        var quality = 50;
        
        appcan.ready(function() {
            appcan.initBounce();
            flag = false;
        })
        
        function countPrice(isbn)
        {
            var request = appcan.require('request');
            request.ajax({
                type : 'POST',
                url : 'http://whynothappy.sinaapp.com/bookinfo',
                data : {username : username, isbn : isbn},
                contentType: 'application/json',
                success:function(data){
                    //alert(data);
                    data = eval("(" + data + ")");
                    makePrice(data);
                },
                error:function(){
                    alert("can't connect the Internet");
                }
            })
        }
        
        function makePrice(data)
        {
            price = parseFloat(data.price);
            document.getElementById('price').value = price * 0.5;
        }
        function ScannerSuccessCallBack(opCode, dataType, data) {
                var obj = eval('('+data+')');
                switch(dataType){
                        case cText:
                                alert("uex.cText");
                                break;
                        case cJson:
                          document.getElementById('scanner').value = obj.code;
                          countPrice(obj.code);
                          break;
                        case cInt:
                            alert("uex.cInt");
                            break;
                          default:
                            alert("error");
                        }
                        
        }
        function ScannerFailedCallBack(data){
                alert(data);
        }

        window.uexOnload = function(){
                uexScanner.cbOpen = ScannerSuccessCallBack;
                uexWidgetOne.cbError = ScannerFailedCallBack;
        }
        
        var lv1 = appcan.listview({
            selector : "#listview1",
            type : "thinLine",
            hasIcon : false,
            hasAngle : false,
            hasControl : true,
        });
        lv1.set([{
            title : '<ul class="ub t-bla ub-ac ">' + '<li class="ub-f1 ut-s ulev-app1">有笔迹(4折)</li>' + '</ul>',
            "switchBtn" : {
                value : false,
                mini : true,
                idx: 0
            }
        }, {
            title : '<ul class="ub t-bla ub-ac">' + '<li class="ub-f1 ut-s ulev-app1">有水印(3折)</li>' + '</ul>',
            "switchBtn" : {
                value : false,
                mini : true,
                idx : 1
            }
        }, {
            title : '<ul class="ub t-bla ub-ac">' + '<li class="ub-f1 ut-s ulev-app1">有笔迹+有水印(2折)</li>' + '</ul>',
            "switchBtn" : {
                value : false,
                mini : true,
                idx : 2
            }
        }, {
            title : '<ul class="ub t-bla ub-ac">' + '<li class="ub-f1 ut-s ulev-app1">有笔迹+有水印+有缺页(1折)</li>' + '</ul>',
            "switchBtn" : {
                value : false,
                mini : true,
                idx : 3
            }
        }]);

        lv1.on("switch:change", function(ele, context, obj, subobj) {
            if (document.getElementById('price').value != "") {
                if (context.switchBtn.idx == 0) {
                    if (context.switchBtn.value) {
                        a = 0.4;
                    }
                    else {
                        a = 0.5;
                    }
                }
                else if (context.switchBtn.idx == 1) {
                    if (context.switchBtn.value) {
                        b = 0.3;
                    }
                    else {
                        b = 0.5;
                    }
                }
                else if (context.switchBtn.idx == 2) {
                    if (context.switchBtn.value) {
                        c = 0.2;
                    }
                    else {
                        c = 0.5;
                    }
                }
                else if (context.switchBtn.idx == 3) {
                    if (context.switchBtn.value) {
                        d = 0.1;
                    }
                    else {
                        d = 0.5;
                    }
                }
                var qual = min(min(a,b),min(c,d));
                document.getElementById('price').value = price * qual;
                quality = qual * 100;
            }
        })
        
        function min(a, b)
        {
            if (a < b) return a;
            return b;
        }
        appcan.button("#submit", "ani-act", function() {
            appcan.alert("提示", "确定卖出书籍？", ["确定", "取消"], send);
           
            
        })
        
        function send(e,idx){
            if (idx == 1) return;
            if (username == null) username = "1";
            var isbn = document.getElementById('scanner').value;
            if (isbn == "") 
            {
                alert("no isbn");
                return;
            }
            var price = document.getElementById('price').value;
            if (price == "")
            {
                alert("no price");
                return;
            }
            var request = appcan.require('request');
            //alert(username + " " + isbn + " " + price + " " + quality);
            request.ajax({
                type : 'POST',
                url : 'http://whynothappy.sinaapp.com/sell',
                data : {username : username, isbn : isbn, price : price, quality : quality},
                contentType: 'application/json',
                success:function(data){
                    //alert(data);
                    data = eval("(" + data + ")");
                    alert("贩卖成功");
                },
                error:function(){
                    alert("can't connect the Internet");
                }
            })
        }
        
        appcan.button("#saoyisao", "ani-act", function() {
            uexScanner.open();
        })
 </script>
</html>